<!--
 * @Descripttion: 直播列表
 * @Author: xiao li
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-29 13:56:02
-->
<template>
    <div class="lb-sys-sproconfig">
        <top-nav></top-nav>
        <div class="page-main">
          <lb-tips>
            <p>{{$t('menu.updateLiveList')}}每天仅能调用 500 次，请合理分配调用频次。详情请查阅<i @click="toJump" style="color:red">《微信小程序直播运营操作手册》</i></p>
          </lb-tips>

          <el-row class="page-top-operate">
            <lb-button size='medium' type='primary' @click="toSyncLive">{{$t('menu.updateLiveList')}}</lb-button>
          </el-row>
          <div class="page-search-form">
            <el-form @submit.native.prevent :inline="true" :model="searchForm" ref="searchForm">
              <el-form-item label="状态" prop="status">
                <el-select  @change="typeChange" v-model="searchForm.status" placeholder="请选择">
                    <el-option
                    v-for="item in typeOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    >
                    </el-option>
                </el-select>
            </el-form-item>
              <el-form-item label="开播时间" prop="date">
              <el-date-picker
                v-model="searchForm.date"
                type="date"
                placeholder="选择日期"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd">
              </el-date-picker>
              </el-form-item>
              <el-form-item label="标题" prop="name">
                <el-input v-model="searchForm.name" placeholder="请输入标题"></el-input>
              </el-form-item>
              <el-form-item>
                <lb-button size="medium" type="primary" icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)">{{$t('action.search')}}</lb-button>
                <lb-button size="medium" icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')">{{$t('action.reset')}}</lb-button>
              </el-form-item>
            </el-form>
          </div>
            <el-table
            v-loading="loading"
            :data="tableData"
          :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
            style="width: 100%">
            <el-table-column
              prop="roomid"
              width="80"
              label="房间ID">
            </el-table-column>
            <el-table-column
              prop="share_img"
              width="100"
              label="封面">
                <template slot-scope="scope">
                  <lb-image :src="[scope.row.share_img]" />
                </template>
            </el-table-column>
            <el-table-column
              prop="name"
              width="200"
              show-overflow-tooltip
              label="标题">
            </el-table-column>
            <el-table-column
              prop="anchor_name"
              label="主播昵称">
            </el-table-column>
            <el-table-column
              prop="start_time"
              label="开播/结束时间">
              <template slot-scope="scope">
                <div>{{scope.row.start_time}} ~ {{scope.row.end_time | handleTime}}</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="time_length"
              label="直播时长">
            </el-table-column>
            <el-table-column
              prop="live_status"
              label="状态">
              <template slot-scope="scope">
                <div>{{live_status[scope.row.live_status]}}</div>
              </template>
            </el-table-column>
          </el-table>
          <lb-page
          :batch='false'
          :page='searchForm.page'
          :pageSize='searchForm.limit'
          :total='total'
          @handleSizeChange='handleSizeChange'
          @handleCurrentChange='handleCurrentChange'
          >
          </lb-page>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      live_status: {
        101: '直播中',
        102: '未开始',
        103: '已结束',
        104: '禁播',
        105: '暂停中',
        106: '异常',
        107: '已过期'
      },
      typeOptions: [{
        id: 0,
        name: '全部'
      }, {
        id: 101,
        name: '直播中'
      }, {
        id: 102,
        name: '未开始'
      }, {
        id: 103,
        name: '已结束'
      }, {
        id: 104,
        name: '禁播'
      }, {
        id: 105,
        name: '暂停中'
      }, {
        id: 106,
        name: '异常'
      }, {
        id: 107,
        name: '已过期'
      }],
      searchForm: {
        status: 0,
        date: '',
        name: '',
        limit: 10,
        page: 1
      },
      total: 0,
      tableData: []
    }
  },
  created () {
  },
  activated () {
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    async toSyncLive () {
      await this.$api.liveGetLive()
      this.handleCurrentChange(1)
    },
    async getTableDataList (flag) {
      if (flag) {
        this.searchForm.page = 1
        this.tableData = []
      }
      this.loading = true
      let {searchForm} = this
      let {code, data} = await this.$api.liveLiveList(searchForm)
      this.loading = false
      if (code !== 200) return
      this.tableData = data.data
      this.total = data.total
    },
    toJump () {
      window.open('https://res.wx.qq.com/mmbizwxampnodelogicsvr_node/dist/images/help_0f7865.pdf', '_blank')
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
    .el-input,
    .el-select{
      width: 200px;
    }
    .dialog-inner{
      height: 300px;
      .el-image{
        width: 200px;
        height: 200px;
        margin: 0 auto;
      }
    }
</style>
